package com.kaifamiao.loader;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class MyClassLoaderTest {

    public static void main(String[] args) throws Exception {

        String path = "D:/kaifamiao/codes/java-advanced/classloader/bytecodes";
        ClassLoader cl = new MyClassLoader( path );
        // 加载指定的类
        Class<?> c = cl.loadClass( "com.kaifamiao.Monkey" );
        System.out.println( c );

        System.out.println( "- ".repeat(30) );

        Constructor<?> con = c.getConstructor( String.class );
        Object x = con.newInstance( "孙悟空" );

        Method m = c.getMethod( "toString" );
        Object res = m.invoke( x );
        System.out.println( res );
    }

}
